home *** CD-ROM | disk | FTP | other *** search
- Path: info.uah.edu!oreo!gbacon
- From: gbacon@oreo (Greg Bacon)
- Newsgroups: comp.lang.c
- Subject: Re: Trouble with file return code.
- Date: 11 Jan 1996 03:56:34 GMT
- Organization: The University of Alabama in Huntsville
- Message-ID: <4d21pj$mi5@info.uah.edu>
- References: <tcpnntpd.16.1.10.20.22.42.2781597121.333610@the-fix.sos.on.ca>
- NNTP-Posting-Host: oreo.aspire.cs.uah.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- xenon@the-fix.sos.on.ca wrote:
- : Im having some trouble getting fread to return NULL when it can't
- : find a specific file...
-
- : else if((ptr=fread(filename1,"rb"))!=NULL)
- : {
- : //do this }
- : else {
- : // do that
- : // this never executes, even if NULL is returned.
- : No matter the file, Null is never returned. Although, when the variable
- : ptr is outputed, the value shown is "0".
- : thankx
- : xenon@the-fix.sos.on.ca
-
- I see a few problems with your code:
-
- First off, // is not a standard C comment delimiter. The C Standard states
- that /* and */ surround comments.
-
- Next, it looks like you're expecting a pointer from fread(). Page 247 of
- K&R II gives this prototype for fread():
-
- size_t fread(void *ptr, size_t size, size_t nobj, FILE *stream);
-
- Oh yeah.. and there's also that technicality of correct ordering of
- parameters. Depending on the implementation, fread() may return 0 on
- error or you may have to use feof() and ferror() and determine status.
-
- Cheers,
- Greg
- --
- Greg Bacon <gbacon@cs.uah.edu>
- University of Alabama in Huntsville
- CS Department Systems Support Team
-